package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShopCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: sky-take-out
 * @description:
 * @author: fmp
 * @create: 2023-04-09 15:10
 * @Version 1.0
 **/
@Slf4j
@RestController
@Api(tags = "购物车接口")
@RequestMapping("/user/shoppingCart")
public class ShopCartController {
    @Resource
    private ShopCartService shopCartService;
    //查看购物车
    @ApiOperation("查看购物车")
    @GetMapping("/list")
    public Result SelectShopCart(){
        List<ShoppingCart> shopCartList = shopCartService.SelectShopCart();
        return Result.success(shopCartList);
    }
    //添加购物车
    @ApiOperation("添加购物车")
    @PostMapping("/add")
    public Result InsertShopCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shopCartService.InsertShopCart(shoppingCartDTO);
        return Result.success();

    }
    //清空购物车
    @ApiOperation("清空购物车")
    @DeleteMapping("/clean")
    public Result CleanShoppingCart(){
        shopCartService.CleanShoppingCart();
        return Result.success();
    }
    //删除购物车中一个商品
    @ApiOperation("删除购物车中一个商品")
    @PostMapping("/sub")
    public  Result SubShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shopCartService.SubShoppingCart(shoppingCartDTO);
        return Result.success();
    }

}
